package frame.options.simulation.results.sdn.graphical;

import java.awt.Color;
import java.awt.Paint;

import model.components.nodes.node.Node;
import model.components.nodes.node.sdn.SdnNode;
import model.components.nodes.node.sdn.SdnServer;

import org.apache.commons.collections15.Transformer;

public class SdnNodeColorTransformer implements Transformer< Node, Paint >
{
	@Override
	public Paint transform( Node node )
	{
		if( node.isSelected() )
			return Color.GREEN;
		

			
		
		if( node.getType().equals( Node.ROUTER_TYPE ) || node.getType().equals( Node.SWITCH_TYPE ) )
		{
			SdnNode sdnNode = (SdnNode) node;
			
			if( sdnNode.getAvailableCPU() < sdnNode.getCPU() * 0.2 || sdnNode.getAvailableRAM() < sdnNode.getRAM() * 0.2  )
			    return Color.RED;
			
			else if( sdnNode.getAvailableCPU() < sdnNode.getCPU() || sdnNode.getAvailableRAM() < sdnNode.getRAM() )
				return Color.YELLOW;
		}
		else if( node.getType().equals( Node.SERVER_TYPE ) )
		{
			SdnServer sdnServer = (SdnServer) node;
			
			if( sdnServer.getAvailableCPU() < sdnServer.getCPU() * 0.2 || sdnServer.getAvailableRAM() < sdnServer.getRAM() * 0.2 || sdnServer.getAvailableStorage() < sdnServer.getStorage() * 0.2 )
			    return Color.RED;
			
			else if( sdnServer.getAvailableCPU() < sdnServer.getCPU() || sdnServer.getAvailableRAM() < sdnServer.getRAM() || sdnServer.getAvailableStorage() < sdnServer.getStorage() )
				return Color.YELLOW;
		}
		
		if( ((SdnNode)node).isController() )
		{
			return Color.BLUE;
		}
		else 
			return Color.BLACK;
	}

}
